import socket
import struct


HOST = "10.10.14.24"
DES_IP = "239.100.1.100"
PORT = 8007

# 创建UDP socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
# 允许端口复用
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# 绑定监听多播数据包的端口
s.bind((HOST, 8007))
# 声明该socket为多播类型
s.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)
# 加入多播组，组地址由第三个参数制定
s.setsockopt(
    socket.IPPROTO_IP,
    socket.IP_ADD_MEMBERSHIP,
    socket.inet_aton(DES_IP) + socket.inet_aton(HOST)
)
s.setblocking(False)
s.sendto(f"->Hello".encode(), (DES_IP, 8008))
